class Solution {
public:
    bool isSubsequence(string s, string t) {
        int n1 = s.size(),n2 = t.size(),left1 = 0,left2 = 0;
        for(;left1 < n1;left1++){
            while(left2 < n2 && t[left2] != s[left1])
                left2++;
            if(left2 == n2)
                return false;
            left2++;
            
        }
        return true;
    }
};
bool isSubsequence(string& s, string& t) {
    int n1 = s.size(), n2 = t.size(), left1 = 0, left2 = 0;
    for (; left1 < n1; left1++) {
        while (left2 < n2 && t[left2] != s[left1])
            left2++;
        if (left2 == n2)
            return false;
        left2++;
    }
    return true;
}
class Solution {
public:
    string findLongestWord(string s, vector<string>& dictionary) {
        string ans;
        for(auto & e :dictionary){
            if(e.size() >= ans.size() && isSubsequence(e,s)){
                if(e.size() == ans.size())
                    ans = min(ans,e);
                else{
                    ans = e;
                }
            }
        }
        return ans;
    }
};


class Solution {
public:
    int appendCharacters(string s, string t) {
        int n1 = s.size(),n2 = t.size();
        int left1 = 0,left2 = 0;
        for(;left1 < n1;left1++){
            if(left2 < n2 && s[left1] == t[left2]){
                left2++;
            }
        }
        return n2 - left2;
    }
};
class Solution {
public:
    bool canMakeSubsequence(string str1, string str2) {
        int n1 = str1.size(), n2 = str2.size();
        int left1 = 0, left2 = 0;
        for (; left1 < n1; left1++) {
            if(left2 < n2 && (str1[left1] == str2[left2] || str1[left1] + 1 == str2[left2] || str1[left1] -25== str2[left2]))
                left2++;
        }
        return left2 == n2;
    }
};
bool fun(string& p,string& str){
    int n1 = p.size(),n2 = str.size();
    int a1 = 0,a2 = 0;
    for(;a1 < n1&&a2 < n2; )
    { 
        if(p[a1] == str[a2]){
            a1++,a2++;
        }else{
            if(str[a2] >= 'a')
                a2++;
            else
                return false;
        }
    }
    for(int j = a2;j < n2;j++){
        if(str[j] <= 'Z')
            return false;
    }
    return a1 == n1;
}
class Solution {
public:
    vector<bool> camelMatch(vector<string>& queries, string pattern) {
        vector<bool> ans;
        cout << (int)'a'<< endl; 
        cout << (int)'A'<< endl; 
        for(auto&str:queries){
            ans.push_back(fun(pattern,str));
        }
        return ans;
    }
};
bool fun(vector<int>& nums1, vector<int>& nums2, int x) {
    int nn = 2;
    int j = 0;
    for (int i = 0; i < nums2.size(); i++) {
        while (nums1[j] + x != nums2[i]) {
            j++;
            if (nn == 0)
                return false;
            --nn;
        }
        j++;
    }
    return true;
}
class Solution {
public:
    int minimumAddedInteger(vector<int>& nums1, vector<int>& nums2) {
        sort(nums1.begin(), nums1.end());
        sort(nums2.begin(), nums2.end());
        int x = 1000000;
        int t = 0;
        for (int i = 0; i <= 2; i++) {
            t = nums2[0] - nums1[i];
            if (fun(nums1, nums2, t)) {
                x = min(x, t);
            }
        }
        return x;
    }
};
bool fun(string& s1, string& s2) {
	size_t i = 0;
	for (size_t j = 0; j < s2.size(); j++) {
		if (s1[i] == s2[j]) {
			i++;
			if (i == s1.size()) {
				//s1是s2的子串
				return true;
			}
		}
	}
	return false;
}
class Solution {
public:
	int findLUSlength(vector<string>& strs) {
		size_t ans = 0;
		for (int i = 0; i < strs.size(); i++) {
			if (strs[i].size() < ans) {
				continue;
			}
			bool tmp = false;
			for (int j = 0; j < strs.size(); j++) {
				if (i!=j && fun(strs[i], strs[j])) {
					//cout << strs[i] << ' ' << strs[j] << '|';
					tmp = true;
					break;
				}
			}
			if (tmp == false) {
				ans = strs[i].size();

			}
		}
		if (ans == 0) {
			return -1;
		}
		return ans;
	}
};